home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Misc / RZToDoList / Source / ToDoServer.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.3 KB  |  122 lines

  1. /* 
  2.  * ToDoServer - implements DO connectivity to the ToDo application
  3.  *
  4.  * You may freely copy, distribute and reuse the code in this example.
  5.  * This code is provided AS IS without warranty of any kind, expressed 
  6.  * or implied, as to its fitness for any particular use.
  7.  *
  8.  * Copyright 1995 Ralph Zazula (rzazula@next.com).  All Rights Reserved.
  9.  *
  10.  */
  11.  
  12. #import "ToDoServer.h"
  13. #import "_ToDoServer.h"
  14. #import "ToDoController.h"
  15. #import "FullCopyList.h"
  16. #import "ToDoItemPublic.h"
  17. #import <machkit/NXProtocolChecker.h>
  18. #import <remote/transport.h>
  19. #import <remote/NXConnection.h>
  20.  
  21. #define _controller _reservedToDoServer1
  22.  
  23. @implementation ToDoServer(Private)
  24.  
  25. - _setController:(id <ToDoServerProtocol>)aController
  26. {
  27.     _controller = aController;
  28.     return self;
  29. }
  30.  
  31. @end
  32.  
  33. @implementation ToDoServer
  34.  
  35. - init
  36. {
  37.     if(self = [super init]) {
  38.         id protocolChecker = [[NXProtocolChecker alloc] initWithObject:self 
  39.                                         forProtocol:@protocol(ToDoServerProtocol)];
  40.         id conn = [NXConnection registerRoot:protocolChecker withName:TODO_PORT];
  41.             
  42.         [conn setDelegate:self];
  43.         [conn runFromAppKit];
  44.     }
  45.     return self;
  46. }
  47.  
  48. - free
  49. {
  50.     if(clientList) {
  51.         clientList = [[clientList freeObjects] free];
  52.     }
  53.     return [super free];
  54. }
  55.     
  56. - itemList
  57. {
  58.     int i;
  59.     id toDoList, returnList = nil;
  60.  
  61.     if(!_controller) {
  62.         return self;
  63.     }
  64.     
  65.     toDoList = [_controller toDoList];
  66.     if(toDoList ? [toDoList count] : 0) {
  67.         returnList = [[FullCopyList alloc] init];
  68.         for(i=0; i<[toDoList count]; i++) {
  69.             [returnList addObject:[[ToDoItemPublic alloc] 
  70.                             initFromItem:[toDoList objectAt:i]]];
  71.         }
  72.     }
  73.     return returnList;
  74. }
  75.  
  76. - addItem:anItem
  77. {
  78.     if(_controller) {
  79.         [_controller addItem:anItem];
  80.     }
  81.     return self;
  82. }
  83.  
  84. - registerForNotification:(id <ToDoNotifications>)sender
  85. {
  86.     if(!clientList) {
  87.         clientList = [[List alloc] init];
  88.     }
  89.     [clientList addObject:sender];
  90.     return self;
  91. }
  92.  
  93. /*** invalidation notification ***/
  94.  
  95. - senderIsInvalid:sender
  96. {
  97.     id remoteList = [sender remoteObjects];
  98.     int i;
  99.     
  100.     if(remoteList) {
  101.         /* Remove any clients the sender was vending from our clientList */
  102.         for(i=0; i<[remoteList count]; i++) {
  103.             [clientList removeObject:[remoteList objectAt:i]];
  104.         }
  105.         
  106.         [remoteList free];
  107.     }
  108.     return self;
  109.     
  110. }
  111.  
  112. /*** as the NXConnection's delegate ***/
  113.  
  114. - connection:(NXConnection *)conn didConnect:(NXConnection *)newConn
  115. {
  116.     [newConn registerForInvalidationNotification:self];
  117.     return newConn;
  118. }
  119.  
  120. @end
  121.  
  122.